- /* sifisadd.cpp by K.Tsuru */
- // function ID = 421 BRADIX
- /*************************************************
- SInteger class
- SInteger + unsigned short
- It is used in SInteger ConvToBin(const SLong& m);
- operator++
- result = m+s ( s < BRADIX)
- **************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- void IsAdd(const SInteger& m, fType s, SInteger& result){
- if(s >= BRADIX) m.SetError(m.OUT_OF_RANGE, "IsAdd", 421);
- result = m; // copy
- if(!s) return;
- // result == m
- if(m.Sign(421)<0){
- // m + s = -(|m|-s)
- result.SetSign(1); IsSub(result, s, result); result.SetSign(-1);
- return;
- }
- result.figure[0] += s; // result.figure[0] > 0
- if(result.figure[0] < BRADIX){ result.aTail = 0; return; }
-
- // normalize
- fType* rv = result.figure.Elements();
- fType u = rv[0] >> BRADIX_BITS; // u > 0
- rv[0] &= BRADIX1;
-
- register uint i = 0;
- while(u && i < m.aHead){
- i++;
- u += rv[i];
- rv[i] = u & BRADIX1;
- u >>= BRADIX_BITS;
- }
- if(u){ // for carray. i == m.aHead
- result.aHead++;
- result.Reserve(result.aHead);
- rv = result.figure.Elements();
- result.figure[result.aHead] = u;
- } else result.aHead = m.aHead;
- #ifndef NDEBUG
- result.figure(result.aHead);
- #endif
- i = 0;
- while(!rv[i]) i++;
- result.aTail = i;
- if( 2u*(result.aHead+1) <= result.figure.size() ) result.DoCutDown();
- }
sifisadd.cpp : last modifiled at 2017/03/13 14:31:59(1,373 bytes)
created at 2016/04/25 14:53:17
The creation time of this html file is 2017/10/25 11:09:45 (Wed Oct 25 11:09:45 2017).